﻿<!DOCTYPE html>
<html>
<head>
    <title>Smartflow-Sharp 工作流程列表</title>
    <link href="./Content/layui/css/layui.css" rel="stylesheet" />
    <link href="./Content/common.css" rel="stylesheet" />
    <script src="./Content/jquery.min.js"></script>
    <script src="./Content/layui/layui.all.js"></script>
    <script src="./Content/common.js?v=1.0"></script>
    <script type="text/javascript">
        function delWf(id) {
            util.ajaxService({
                type: 'delete',
                url: 'api/structure/delete/' + id,
                success: function () {
                    doGridFresh();
                }
            });
        }

        function openWin(url) {
            var h = window.screen.availHeight;
            var w = window.screen.availWidth;
            window.open(url, '流程设计器', "width=" + w + ", height=" + h + ",top=0,left=0,titlebar=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,toolbar=no,location=no");
        }

        $(function () {
            var table = layui.table;
            table.render({
                elem: '#workflow_structs'
                , page: false
                , defaultToolbar: false
                , url: 'api/structure/get'
                , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                , cols: [[
                    { width: 60, type: 'numbers', sort: false, title: '序号', align: 'center', unresize: true }
                    , { field: 'StructName', width: 240, title: '名称', align: 'left' }
                    , { field: 'CateName', width: 100, title: '业务类型', sort: false, align: 'center' }
                    , { field: 'Status', width: 120, title: '状态', align: 'center', templet: '#struct_col_checkbox', unresize: true }
                    , { field: 'Memo', title: '备注', minWidth: 120, align: 'left' } //minWidth：局部定义当前单元格的最小宽度，layui 2.2.1 新增
                    , { fixed: 'right', title: '操作', toolbar: '#struct_col_tool', width: 150, align: 'center' }
                ]]
            });

            //监听行工具事件
            table.on('tool(workflow_structs)', function (obj) {
                var data = obj.data;
                var eventName = obj.event;
                switch (eventName) {
                    case "del":
                        layer.confirm('删除？', function (index) {
                            delWf(data.NID);
                            layer.close(index);
                        });
                        break;
                    case "edit":
                        openWin('./design.html?id=' + data.NID);
                        break;
                    default:
                        break;
                }
            });

            //监听锁定操作
            layui.form.on('checkbox(Use_Status)', function (obj) {
                var id = $(obj.elem).attr('identity');
                var useState = (obj.elem.checked ? 1 : 0);
                $.ajax({
                    type: 'put',
                    url: 'api/structure/put',
                    data: { Status: useState, NID: id },
                    success: function () {
                        layui.table.reload('workflow_structs');
                    }
                });
            });
        });

        function doGridFresh() {
            layui.table.reload('workflow_structs');
        }
    </script>
</head>
<body>
    <br />
    <div class="layui-container">
        <div class="layui-btn-group">
            <input type="button" value="增加" class="layui-btn  layui-btn-sm" onclick="openWin('./design.html')" />
        </div>
        <table class="layui-hide" id="workflow_structs" lay-filter="workflow_structs"></table>
    </div>
    <script type="text/html" id="struct_col_tool">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>

    <script type="text/html" id="struct_col_checkbox">
        <input type="checkbox" name="Status" value="{{d.Status}}" identity="{{d.NID}}" title="启用" lay-filter="Use_Status" {{ d.Status == 1 ? 'checked' : '' }}>
    </script>
</body>
</html>
